<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
use think\Response;
use utils\workerman\Request;

Route::get('think', function () {
    return 'hello,ThinkPHP6!';
});

Route::get('hello/:name', 'index/hello');
Route::any('/[path:.+]', function (Request $request, $path = '') {
    halt($path);
    // 静态文件目录
    $static_base_path = root_path() . '/public';
    // 安全检查，避免url里 /../../../password 这样的非法访问
    if (strpos($path, '..') !== false) {
        return response('<h1>400 Bad Request</h1>', 400);
    }
    // 文件
    $file = "$static_base_path/$path";
    if (!is_file($file)) {
        return response('<h1>404 Not Found</h1>', 404);
    }
    return Response::create($file, 'file', 200);
})->ext('shtml|html');;